const db = wx.cloud.database();

Page({
  data: {
    imgUrls: [],
    indicatorDots: false,
    autoplay: false,
    interval: 3000,
    duration: 800,
    goodsList:[],
    page_num:1,//默认请求第一页数据
    pageIndex:0,
    pageSize:6,
    isLoading:false
  },
  onLoad:function(option){
  this.getSwiper()
  this.getGoodsList(this.data.pageIndex,this.data.pageSize)

   
  },
  /**获取轮播图数据 */
  getSwiper(){
    db.collection("sg_swiper").get({
      success:(res)=>{
        console.log(res.data)
        this.setData({
         imgUrls:res.data
        })
      },
      error:(err) =>{
       console.log(err)
      }
    })
  },
  
  seeGoodsDertail:function(option){
    let goods_id=option.currentTarget.dataset.id
    console.log(goods_id)
    wx.navigateTo({
      url: 'details/details?id='+goods_id,
    })
   },
   /**分页获取商品数据 */
  getGoodsList(pageIndex,pageSize){
    db.collection("sg_goods").skip(pageIndex*pageSize).limit(pageSize).get({
      success:(res)=>{
        res.data.length==0?this.setData({isLoading:true}):this.setData({goodsList:this.data.goodsList.concat(res.data)}) 
        wx.hideLoading() 
      }
    })
  },
   onReachBottom: function () {
   
    // 显示加载图标
    wx.showLoading({
      title: '玩命加载中',
    })
    // 页数+1
    this.setData({
        pageIndex:this.data.pageIndex + 1 //每次下拉，页数+1
        
    })
      this.getGoodsList(this.data.pageIndex,this.data.pageSize)
    
    
    
    
 
  },

})